#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	int m,k,n;cin >> n;
	while (n--)
	{
		cin >> m;
		switch (m)
		{
		case 1: cin >> k;q.push(k);break;
		case 2: if (q.empty()) cout << "ERR_CANNOT_POP" << endl;else q.pop();break;
		case 3:if (q.empty())cout << "ERR_CANNOT_QUERY" << endl;else cout << q.front() << endl;break;
		case 4:cout << q.size() << endl; break;
		}
	}
	return 0;
}